<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { auditApi } from '@/api/controller';
  import { parseTime } from '@/utils/index';
  import { Toastloading } from '@/utils/public';
  import Pagination from "@/components/Pagination/index.vue";
  import xmImage from '@/components/xmImage/index.vue';
  import solveForm from './solveForm.vue';
  const solveFormRef = ref()
  const action = reactive({
    total:0,
    list:[] as any[],
  })
  const listQuery = reactive({
    page: 1,
    limit: 10,
    uuid: '',
    nickname:"",
    fe_content: '',
    fe_status: 0,
    sort: "asc"
  })
  const handleSerach = ()=>{
    listQuery.page = 1
    getList()
  }
  const handleForm = (row:any = {})=>{
    solveFormRef.value.openDialog(row)
  }
  const getList = async()=> {
    const loading = Toastloading()
    const res = await auditApi.getFeedbacks(listQuery)
    loading.close()
    const { data=[], total=0 } = res.data
    action.total = total
    action.list = data
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">用户UUID：</div>
          <el-input v-model="listQuery.uuid" clearable placeholder="请输入用户UUID"/>
        </div>
        <div class="labelItem">
          <div class="label">用户昵称：</div>
          <el-input v-model="listQuery.nickname" clearable placeholder="请输入用户昵称"/>
        </div>
        <div class="labelItem">
          <div class="label">关键字：</div>
          <el-input v-model="listQuery.fe_content" clearable placeholder="请输入关键字"/>
        </div>
        <div class="labelItem">
          <div class="label">处理状态：</div>
          <el-select v-model="listQuery.fe_status" placeholder="请选择处理状态">
            <el-option label="待处理" :value="0"/>
            <el-option label="已处理" :value="1"/>
          </el-select>
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border
    >
      <el-table-column width="90" prop="user.uuid" label="用户UUID" />
      <el-table-column min-width="100" show-overflow-tooltip prop="user.nickname" label="用户昵称" />
      <el-table-column min-width="100" show-overflow-tooltip prop="fe_content" label="反馈内容" />
      <el-table-column min-width="100" show-overflow-tooltip prop="note" label="处理备注" />
      <el-table-column min-width="100" prop="desc" label="反馈图片">
        <template #default="scoped">
          <xmImage style="width: 100px;" :src="scoped.row.fe_imgs[0]" :list="scoped.row.fe_imgs" />
        </template>
      </el-table-column>
      <el-table-column min-width="100" prop="create_timestamp" label="时间">
        <template #default="scoped">
          {{ parseTime(scoped.row.create_timestamp, '{y}-{m}-{d} {h}:{i}') }}
        </template>
      </el-table-column>
      <el-table-column min-width="100" prop="fe_status" label="处理状态">
        <template #default="scoped">
          <el-tag>
            {{ ['待处理','已处理'][scoped.row.fe_status] || scoped.row.fe_status }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column min-width="100" prop="update_time" label="处理时间">
        <template #default="scoped">
          {{ parseTime(scoped.row.update_time, '{y}-{m}-{d} {h}:{i}') }}
        </template>
      </el-table-column>
      <el-table-column width="140" fixend="right" label="操作">
        <template #default="scoped">
          <el-button v-if="scoped.row.fe_status == 0" type="primary" @click="handleForm(scoped.row)">处理反馈</el-button>
          <el-button v-if="scoped.row.fe_status == 1" type="danger" @click="handleForm(scoped.row)">查看备注</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
    <solveForm ref="solveFormRef" @update-list="getList" />
  </div>
</template>